#
# fade colour program in avdl
#
# it fades from black to a colour, then back to black
#
(class worldMain dd_world
	(group

	# tracking timing
	(def float counter)
	(def int positive)
	(def int delay)

	(function void create (group))
	(function void update (group))
	(function void draw (group))
	(function void clean (group))

	)
)

# initialise data
(class_function worldMain void create (group)
	(group

	(dd_clearColour 0 0 0 1)
	(= this.counter 0)
	(= this.positive 1)
	(= this.delay 30)

	)
)

# update each frame
(class_function worldMain void update (group)
	(group

	# on delay do nothing
	(if (> this.delay 0)
		(= this.delay (- this.delay 1))
	# else
		(group

		# update clear colour
		(dd_clearColour (* this.counter 0.8) (* this.counter 0.6) (* this.counter 1) 1)

		# advance animation
		(if this.positive
			(group
			(= this.counter (+ this.counter 0.02))

			(if (>= this.counter 1)
				(group
				(= this.counter 1)
				(= this.positive 0)
				(= this.delay 100)
				)
			)
			)
		# negative advance of animation
			(group
			(= this.counter (- this.counter 0.02))
			(if (<= this.counter 0)
				(group
				(= this.counter 0)
				(dd_clearColour 0 0 0 1)
				)
			)
			)
		)
		)
	) # if delay

	)
) # update

(class_function worldMain void draw (group) (group))
(class_function worldMain void clean (group) (group))

(function void dd_gameInit (group)
	(group

	(dd_setGameTitle "fade - avdl")
	(dd_world_set_default worldMain)

	)
)
